﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CIS470MetricsTracking
{
	public partial class UserLogin : Form
	{
		public UserLogin()
		{
			InitializeComponent();
		}

		private void btnRegister_Click(object sender, EventArgs e)
		{
            lblErrorText.Text = "";
            txtUserEmail.Text = "";
            txtPassword.Text = "";

			UserRegistration user_reg = new UserRegistration();
			user_reg.Show();
			user_reg.BringToFront();
            this.Hide();

            user_reg.FormClosing += RegClosing;
		}

        private void RegClosing(object sender, FormClosingEventArgs e)
        {
            this.Show();
        }

		/*  ////// old function to bypass login /////////
		private void btnLogin_Click(object sender, EventArgs e)
		{
				ProjectSelection proj_select = new ProjectSelection();
				proj_select.Show();
				proj_select.BringToFront();
		}
		*/

		private void btnLogin_Click(object sender, EventArgs e)
		{
			string email = txtUserEmail.Text.ToString().Trim();
			string password = txtPassword.Text.ToString().Trim();

			if (ControllerManager.user_controller.verify_user(email, password)) {
				ProjectSelection proj_select = new ProjectSelection(this);
				proj_select.Show();
				proj_select.BringToFront();
				txtUserEmail.Text = "";
				txtPassword.Text = "";
				lblErrorText.Visible = false;
				this.Hide();
			} else {
				lblErrorText.Text = "Login failed: email or password is incorrect.";
				lblErrorText.Visible = true;
			}
		}

		private void UserLogin_Load(object sender, EventArgs e)
		{

		}
	}
}
